package com.yami.shop.listener;

import com.yami.shop.bean.event.PaySuccessOrderNftEvent;
import com.yami.shop.bean.event.WithdrawalNftEvent;
import com.yami.shop.bean.model.BusinessNft;
import com.yami.shop.bean.model.OrderItem;
import com.yami.shop.bean.order.PaySuccessOrderOrder;
import com.yami.shop.bean.personnft.AddPersonnft;
import com.yami.shop.service.BusinessNftService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

/**
 * 确认订单信息时的默认操作
 *
 * @author LGH
 */
@Slf4j
@Component("defaultWithdrawalNftListener")
@AllArgsConstructor
public class WithdrawalNftListener {

    @Autowired
    private BusinessNftService businessNftService;

    /**
     * 购买持仓增加取币记录
     */
    @EventListener(WithdrawalNftEvent.class)
    @Order(AddPersonnft.AIRDROOP)
    public void defaultWithdrawalNftListener(WithdrawalNftEvent event) {
        log.info("*********************************************************提现空投持仓增加取币记录开始");
        BusinessNft businessNft = new BusinessNft();
        businessNft.setBusinessType(5);
        businessNft.setCreateTime(new Date());
        businessNft.setOutId(event.getOutId());
        businessNft.setStatus(0);
        businessNft.setProdId(event.getProdId());
        businessNft.setProdName(event.getProdName());
        businessNft.setNum(event.getProdCount());
        businessNft.setUserId(event.getUserId());
        businessNftService.save(businessNft);
        log.info("*********************************************************提现空投持仓增加取币记录结束");
    }
}
